from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class ItemBase(BaseModel):
    """商品基础模式"""
    name: str = Field(..., description="商品名称", min_length=1, max_length=100)
    description: str = Field(..., description="商品描述", max_length=500)
    price: float = Field(..., description="商品价格", gt=0)
    category: str = Field(..., description="商品分类", min_length=1, max_length=50)

class ItemCreate(ItemBase):
    """创建商品请求模式"""
    pass

class ItemUpdate(BaseModel):
    """更新商品请求模式"""
    name: Optional[str] = Field(None, description="商品名称", min_length=1, max_length=100)
    description: Optional[str] = Field(None, description="商品描述", max_length=500)
    price: Optional[float] = Field(None, description="商品价格", gt=0)
    category: Optional[str] = Field(None, description="商品分类", min_length=1, max_length=50)

class ItemResponse(ItemBase):
    """商品响应模式"""
    id: int = Field(..., description="商品ID")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")

    class Config:
        from_attributes = True

class ItemListResponse(BaseModel):
    """商品列表响应模式"""
    items: list[ItemResponse]
    total: int
    skip: int
    limit: int 